﻿using System;
using Game.ExtensibleObjects;

namespace Game.Map.Extensions
{
    public static class ViewExtensionHelper
    {
        public static ViewExtension ViewX(this IMapField field)
        {
            return field.Extensions.Find<ViewExtension>();
        }
    }

    public class ViewExtensionFactory : IRuntimeExtensionFactory
    {
        public IRuntimeExtension CreateExtension(IRuntimeExtensibleObject source)
        {
            return new ViewExtension();
        }
    }

    public class ViewEventArgs : EventArgs
    {
        readonly ViewExtension _Extension;

        public ViewEventArgs(ViewExtension extension)
        {
            _Extension = extension;
        }

        public ViewExtension Extension
        {
            get { return _Extension; }
        }
    }

    public enum GameImage
    {
        None, MoveArrow, AttackArrow, Square
    }

    public class ViewExtension : IRuntimeExtension
    {
        public event EventHandler<ViewEventArgs> Changed;

        GameImage _GameImage;

        public GameImage GameImage
        {
            get { return _GameImage; }
            set
            {
                if (_GameImage != value)
                {
                    _GameImage = value;
                    FireChanged();
                }
            }
        }

        void FireChanged()
        {
            if (Changed != null)
            {
                Changed(this, new ViewEventArgs(this));
            }
        }
    }
}

